# -*- encoding:utf-8 -*-
from mycelery.main import app
from luffyapi.settings import constants
from datetime import datetime
from order.models import Order
@app.task(name="check_order")
def check_order():
    """检测订单是否超时，超时就修改订单状态变为超时取消"""
    print('检查订单是否过期')
    # 超时条件： 当前时间 > (订单生成时间 + 超时时间)   =====>>>>  (当前时间 - 超时时间) > 订单生成时间
    now_timestamp = datetime.now().timestamp()
    #订单过期时间
    timeout_number = now_timestamp - constants.ORDER_OUTTIME
    timeout_date_string = datetime.fromtimestamp(timeout_number)
    order_outtime_list = Order.objects.filter(order_status=0, created_time__lte=timeout_date_string)
    if len(order_outtime_list) > 0:
        for order in order_outtime_list:#过期的列表
            order.order_status = 3
            order.save()




































